<template>
	<view >
		<MyInput 
			label="名字" 
			v-model="dormitoryName" 
			:borderColor="primary_cool_color"
			:placeholder="dormitory.dormitoryName"/>
	</view>
</template>

<script setup>
	import { ref , watch , defineEmits} from "vue"
	
	import MyInput from '@/components/MyInput/MyInput.vue'
	
	import {DormitoryModel} from '@/service/model/dormitory.js'
	
	import {DormitoryState} from '@/enum/GlobalEnum.js'
	
	import {
		dynamicStyleStore
	} from '@/stores/dynamicStyle.js'
	
	const dynamicStyle_store = dynamicStyleStore()
	
	const {
		primary_cool_color
	} = dynamicStyle_store.dormitoryStyle	
	
	const props=defineProps({
		clickSubmitDormitoryNameFlag:{
			type:Number
		},
		dormitory:{
			type:Object
		},
		dormitoryAllId:{
			type:Object
		}
	})
	const emits=defineEmits(['setDormitoryNameOk'])
	
	watch(()=>props.clickSubmitDormitoryNameFlag,()=>{
		submitDormitoryName()
	})
	
	const dormitoryName = ref(props.dormitory?.dormitory_name)
	
	const dormitoryModel = new DormitoryModel()
	
	//提交修改名字
	const submitDormitoryName=async()=>{
		
		if(!dormitoryName.value.trim()){
			uni.$emit('tips','请输入有效的名字!','warn')
			return
		}
		
		const {data,success} = await dormitoryModel.patchSetDormitoryInfo({
			"dormitory_name" : dormitoryName.value,
			"descript":props.dormitory.descript,
			"type":DormitoryState.NORMAL
		},props.dormitoryAllId.dormitory_id)
		
		if(success){
			dormitoryName.value=''
			uni.$emit('tips',data,'success')
			emits('setDormitoryNameOk',data)
		}
	}
</script>

<style lang="less">
	
</style>